package io.renren.modules.avanotes.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.RedisUtils;
import io.renren.common.vo.output.SpecialSubjectVo;
import io.renren.modules.avanotes.dao.ReferenceBankDao;
import io.renren.modules.avanotes.dao.SpecialSubjectDao;
import io.renren.modules.avanotes.entity.ReferenceBankEntity;
import io.renren.modules.avanotes.entity.ReferenceMaterialEntity;
import io.renren.modules.avanotes.entity.SpecialSubjectEntity;
import io.renren.modules.avanotes.service.ReferenceBankService;
import io.renren.modules.avanotes.service.SpecialSubjectService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


//@Service("referenceBankService")//默认只有一个实现，那就不写名称了直接使用默认的名称！
@Service
public class ReferenceBankServiceImpl extends ServiceImpl<ReferenceBankDao, ReferenceBankEntity> implements ReferenceBankService {

    @Autowired
    RedisUtils redisUtils;

    public static final String[] simpleColumnArr = {ReferenceBankEntity.CN_ID, ReferenceBankEntity.CN_NAME
            , ReferenceBankEntity.CN_DIGEST};

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ReferenceBankEntity> page = this.page(
                new Query<ReferenceBankEntity>().getPage(params),
                new QueryWrapper<ReferenceBankEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * key=referenceBankAllMap::getAllMap
     * @param type
     * @return
     */
    @Cacheable(value = {"referenceBankAllMap"}, key = "#root.methodName")
    @Override
    public Map<Integer, String> getAllMap(Integer type) {
        List<ReferenceBankEntity> list = this.list(new QueryWrapper<ReferenceBankEntity>().select(simpleColumnArr).eq(ReferenceBankEntity.CN_TYPE, type));

        Map<Integer, String> map = new HashMap<>();
        for (ReferenceBankEntity entity : list) {
            map.put(entity.getId(), entity.getName() + "/" + entity.getDigest());
        }
        return map;
    }


}